package com.gitee.wsl.data.recycler

import com.gitee.wsl.data.recycler.RecyclerPool.WithPool

/**
 * Intermediate base class for instances that are stateful and require
 * special handling with respect to JDK serialization, to retain
 * "global" reference distinct from non-shared ones.
 */
abstract class StatefulImplBase<P : WithPool<P>>
protected constructor(
    /**
     * Value that indicates basic aspects of pool for JDK serialization;
     * either marker for shared/non-shared, or possibly bounded size;
     * depends on sub-class.
     */
    protected val _serialization: Int,
) : RecyclerPool<P> {
    protected fun _resolveToShared(shared: StatefulImplBase<P>): StatefulImplBase<P>? {
        if (_serialization == SERIALIZATION_SHARED) {
            return shared
        }
        return null
    }

    abstract fun createPooled(): P

    companion object {
        const val SERIALIZATION_SHARED: Int = -1

        const val SERIALIZATION_NON_SHARED: Int = 1
    }
}


